package com.ldatum.crm.daoImpl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.ldatum.crm.dao.TPositionDao;
import com.ldatum.crm.domain.TPosition;
import com.ldatum.crm.util.HibernateUtil;

public class TPositionDaoImpl implements TPositionDao {

	@Override
	public List<TPosition> list(Class<TPosition> class1) {
		Session s = null;
		try {
			s = HibernateUtil.getSession();
			String hql = "from TPosition as position ";
			Query q = s.createQuery(hql);
			@SuppressWarnings("unchecked")
			List<TPosition> list = (List<TPosition>) q.list();
			
			return list;
		}finally{
			if(s!=null){
				s.close();
			}
		}
	}

	@Override
	public List<TPosition> findByDepartId(int departId) {
		Session s = null;
		try {
			s = HibernateUtil.getSession();
			String hql = "from TPosition as position where depart_id = :departId";
			Query q = s.createQuery(hql);
			q.setInteger("departId", departId);
			@SuppressWarnings("unchecked")
			List<TPosition> list = (List<TPosition>) q.list();
			
			return list;
		}finally{
			if(s!=null){
				s.close();
			}
		}
	}

}
